package array

func TwoSum(nums []int, target int) []int {
	first := 0

	for ; first < len(nums)-1; first++ {
		for second := first + 1; second < len(nums); second++ {
			if nums[first]+nums[second] == target {
				return []int{first, second}
			}
		}
	}

	return nil
}

func HashTwoSum(nums []int, target int) []int {
	hashTable := map[int]int{}
	for i, v := range nums {
		// p是target-nums[i]的索引
		if p, ok := hashTable[target-v]; ok {
			return []int{p, i}
		}
		// key是nums[i]的值,value是索引
		hashTable[v] = i
	}

	return nil
}
